package com.xiaochong.bitong.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xiaochong.bitong.api.constant.ReturnCode;
import com.xiaochong.bitong.api.service.DownLoadUrlService;
import com.xiaochong.bitong.api.utils.ApiVersion;
import com.xiaochong.tir.common.data.vo.ApiResultVo;
import com.xiaochong.tir.common.util.ApiResultCodeUtils;

/**
 * @author qzw
 * 2018年8月31日 下午4:42:04
 * @description 
 **/
@RestController
@Api(value = "下载地址")
@RequestMapping(value = ApiVersion.API_V1_PREFIX+"/qrcode")
public class QRCodeController {
	
	@Autowired
	private DownLoadUrlService downLoadUrlService;

	/**
	 * app下载地址
	 */
	@ApiOperation(value = "app下载地址" , notes = "app下载地址")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "app类型（1为IOS,2为Android）", required = true, dataType = "String", paramType = "query"),
	})
	@PostMapping("downloadurl")
	public ApiResultVo<String> turnover(@RequestParam(value = "type", required = true) String type){
		ApiResultVo<String> apiResultVo=new ApiResultVo<String>();
		String url = downLoadUrlService.getAppUrl(type);
		if(url == null || "".equals(url.trim())){
			apiResultVo.setCode(ReturnCode.DATA_NOT_EXIST);
			apiResultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
		}else{
			apiResultVo.setCode(ReturnCode.SUCCESS);
			apiResultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
			apiResultVo.setData(url);
		}
		return apiResultVo;
	}
}
